<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:ren="http://www.renyare.ru/NS/templating"
>
<!-- Basic initialisation -->
<xsl:strip-space elements='*'/>

<!-- Initilalise environment variables -->
<xsl:variable name="_ctx" select="/ren:page/ren:context"/>
<xsl:variable name="_root" select="$_ctx/ren:root/text()"/>
<xsl:variable name="_path" select="concat($_root, $_ctx/ren:path)"/>
<xsl:variable name="_env" select="document(concat($_root, '/env.xml'))/environment"/>
<xsl:variable name="_static">
    <xsl:choose>
        <xsl:when test="starts-with($_ctx/ren:static,'/')"><xsl:value-of select="concat($_root, $_ctx/ren:static/text())"/></xsl:when>
        <xsl:when test="starts-with($_ctx/ren:static,'http')"><xsl:value-of select="$_ctx/ren:static/text()"/></xsl:when>
        <xsl:otherwise><xsl:value-of select="concat($_root, $_path, '/', $_ctx/ren:static/text())"/></xsl:otherwise>
    </xsl:choose>
</xsl:variable>
<xsl:variable name="_skin" select="concat($_static, 'skins/', $_ctx/ren:skin/text(), '/')"/>

<xsl:template name="gettext">
<xsl:param name="id" select="@name"/>
<xsl:param name="file"/>
<xsl:apply-templates select="document(concat($lang, $file))/strings/string[@id = $id][1]" mode="gettext"/>
</xsl:template>

<xsl:template match="*" mode="gettext">
<xsl:apply-templates select="./node()" mode="copy"/>
</xsl:template>

<!-- This skips extracting anything from nodes, with no templates matching -->
<xsl:template match="*" mode="module"/>

<xsl:template match="text()" mode="copy">
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="@*|node()" mode="copy">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="copy"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
